home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / HARDWARE.SWG / 0041_CMOS Utility.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  2KB  |  118 lines

  1. program Mem10;
  2.  
  3. uses
  4.   Crt,
  5.   Dos;
  6.  
  7. const
  8.   Max = $63;
  9.  
  10. type
  11.   TCmos = array[0..Max] of Byte;
  12.  
  13. var
  14.   Num, Info, j: Byte;
  15.   i: LongInt;
  16.   Cmos: TCmos;
  17.   F: File of TCmos;
  18.  
  19. procedure WriteCmos;
  20. begin
  21.   Num := 0;
  22.   for i := 0 to Max do begin
  23.     asm
  24.       xor ax, ax
  25.       mov al, Num
  26.       out 70h, al
  27.       in  al, 71h
  28.       mov Info, al
  29.     end;
  30.     Cmos[Num] := Info;
  31.     Inc(Num);
  32.   end;
  33.  
  34.   Assign(F, 'Cmos.Dta');
  35.   Rewrite(F);
  36.   Write(F, Cmos);
  37.   Close(F);
  38. end;
  39.  
  40. procedure OpenFile;
  41. begin
  42.   {$I-}
  43.   Assign(F, 'Cmos.Dta');
  44.   Reset(F);
  45.   Read(F, Cmos);
  46.   Close(F);
  47.   {$I+}
  48.   if IOResult <> 0 then begin
  49.     WriteLn;
  50.     WriteLn('Could not find CMOS.DTA');
  51.     Halt(1);
  52.   end;
  53. end;
  54.  
  55. procedure RestoreCmos;
  56. begin
  57.   OpenFile;
  58.   for j := 0 to Max do begin
  59.     Info := Cmos[j];
  60.     asm
  61.       xor ax, ax
  62.       mov al, j
  63.       out 70h, al
  64.       mov al, Info
  65.       out  71h, al
  66.     end;
  67.   end;
  68. end;
  69.  
  70. procedure Help;
  71. begin
  72.   WriteLn;
  73.   WriteLn('This program can save the values from your CMOS to');
  74.   WriteLn('disk file and then restore them again later.');
  75.   WriteLn('This is helpful if your CMOS gets trashed either');
  76.   WriteLn('because the clock battery dies or because it was');
  77.   WriteLn('accidentally overwritten.');
  78.   WriteLn;
  79.   WriteLn('To use this program, first save the current CMOS');
  80.   WriteLn('to disk by choosing save from the program menu.');
  81.   WriteLn('This creates a file called CMOS.DTA. Don''t lose it.');
  82.   WriteLn('Later, if you have problems, you can restore');
  83.   WriteLn('the CMOS by choosing Restore from the menu,');
  84.   WriteLn('so long as CMOS.DTA is still available.');
  85. end;
  86.  
  87. procedure FlushKeyBuffer;
  88. var
  89.   Recpack : registers;
  90. begin
  91.   with recpack do begin
  92.     Ax := ($0c shl 8) or 6;
  93.     Dx := $00ff;
  94.   end;
  95.   Intr($21,recpack);
  96. end;
  97.  
  98. var
  99.   ch: Char;
  100.  
  101. begin
  102.   ClrScr;
  103.   FlushKeyBuffer;
  104.   WriteLn('A) Restore cmos');
  105.   WriteLn('B) Save cmos');
  106.   WriteLn('C) Help');
  107.   WriteLn('Q) Quit');
  108.   repeat
  109.     ch := UpCase(ReadKey);
  110.   until ch in ['A', 'B', 'C', 'Q'];
  111.  
  112.   case ch of
  113.     'A': RestoreCmos;
  114.     'B': WriteCmos;
  115.     'C': Help;
  116.     'Q':;
  117.   end;
  118. end.